import numpy as np
from sklearn import datasets


def train_test_split(X, y, test_ratio=0.2, seed=None):
    assert X.shape[0] == y.shape[0]
    assert 0 <= test_ratio <= 1

    if seed:
        np.random.seed(seed)

    shuffle_indexes = np.random.permutation(len(X))
    train_indexes_count = int(len(shuffle_indexes) * (1 - test_ratio))

    X_train = X[shuffle_indexes[:train_indexes_count]]
    y_train = y[shuffle_indexes[:train_indexes_count]]
    X_test = X[shuffle_indexes[train_indexes_count:]]
    y_test = y[shuffle_indexes[train_indexes_count:]]

    return X_train, y_train, X_test, y_test
